import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_eve_plugin/components/ye_xiu/checkpoint/app_bar.dart';
import 'package:flutter_eve_plugin/components/ye_xiu/checkpoint/list_view.dart';
import 'package:flutter_eve_plugin/components/ye_xiu/checkpoint/main_footer_view.dart';
import 'package:flutter_eve_plugin/pages/ye_xiu/checkpoint/actions.dart';
import 'package:flutter_eve_plugin/store/main.dart';
import 'package:flutter_eve_plugin/store_vm/app_vm.dart';
import 'package:flutter_eve_plugin/utils/image_util.dart';
import 'package:flutter_eve_plugin/utils/screen_util.dart';
import 'package:flutter_redux/flutter_redux.dart';

class CheckpointMainPage extends StatefulWidget {
  final String title;
  CheckpointMainPage({Key key, this.title}) : super(key: key);

  _CheckpointMainPageState createState() => _CheckpointMainPageState();
}

class _CheckpointMainPageState extends State<CheckpointMainPage> {
  @override
  Widget build(BuildContext context) {
    return StoreConnector<AppState, AppStateViewModel>(onInit: (store) {
      store.dispatch(dungeonList(1));
      store.dispatch(vitality(context));
    }, converter: (store) {
      return AppStateViewModel(state: store.state);
    }, builder: (context, vm) {
      var dungeonVitality = vm.state.yeXiuState.checkpointState.dungeonVitality;
      return Container(
        decoration: BoxDecoration(
            image: DecorationImage(
                image: AssetImage(
                    imageUtilYeXiu('checkpoint/icon_checkpoint_bg@3x')),
                fit: BoxFit.fitWidth,
                alignment: Alignment.topCenter)),
        child: SafeArea(
          child: Scaffold(
            backgroundColor: Colors.transparent,
            appBar: buildNewMainAppBar(dungeonVitality?.currVitality ?? 0,
                dungeonVitality?.totalVitality ?? 0),
            body: Stack(
              children: <Widget>[
                Padding(
                  padding: EdgeInsets.only(bottom: setRatio(45)),
                  child: CheckpointListViewWidget(),
                ),
                Positioned(
                  bottom: 0,
                  child: CheckpointFooterWidget(),
                )
              ],
            ),
          ),
        ),
      );
    });
  }
}
